/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tamnhat.controller;

import com.tamnhat.entity.GameJava;
import com.tamnhat.entity.MediaItem;
import com.tamnhat.model.GameJavaModel;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

/**
 *
 * @author Administrator
 */
public class JavaController implements Serializable {

    private String title;
    private String titleVn;
    private String description;
    private String linkJar;
    private String linkJad;
    private String preview;
    private String fileName;
    private String fileLocation;
    private String contentType;
    private String downloadCount;
    private String itemId;
    private DataModel items;
    private MediaItem current;
    private List<MediaItem> listTable = new ArrayList<MediaItem>();
    private boolean finish = false;

    /**
     * Creates a new instance of JavaController
     */
    public JavaController() {
        try {
            listTable = GameJavaModel.getListCondition(20, "");
            items = new ListDataModel(listTable);
        } catch (Exception e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("ERROR: " + e.getMessage()));
            e.printStackTrace();
        }
    }

    public List<MediaItem> getListTable() {
        return listTable;
    }

    public void setListTable(List<MediaItem> listTable) {
        this.listTable = listTable;
    }

    public boolean isFinish() {
        return finish;
    }

    public void setFinish(boolean finish) {
        this.finish = finish;
    }

    public String getDownloadCount() {
        return downloadCount;
    }

    public void setDownloadCount(String downloadCount) {
        this.downloadCount = downloadCount;
    }

    public String getItemId() {
        return itemId;
    }

    public void setItemId(String itemId) {
        this.itemId = itemId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTitleVn() {
        return titleVn;
    }

    public void setTitleVn(String titleVn) {
        this.titleVn = titleVn;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getLinkJar() {
        return linkJar;
    }

    public void setLinkJar(String linkJar) {
        this.linkJar = linkJar;
    }

    public String getLinkJad() {
        return linkJad;
    }

    public void setLinkJad(String linkJad) {
        this.linkJad = linkJad;
    }

    public String getPreview() {
        return preview;
    }

    public void setPreview(String preview) {
        this.preview = preview;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getFileLocation() {
        return fileLocation;
    }

    public void setFileLocation(String fileLocation) {
        this.fileLocation = fileLocation;
    }

    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    public DataModel getItems() {
        return items;
    }

    public void setItems(DataModel items) {
        this.items = items;
    }

    public MediaItem getCurrent() {
        return current;
    }

    public void setCurrent(MediaItem current) {
        this.current = current;
    }

    public String viewDetail() {
        current = (MediaItem) items.getRowData();
        return "viewDetailJava?faces-redirect=true";
    }

    public String moreGame() {
        try {
            int size = listTable.size();
            List<MediaItem> list = GameJavaModel.getListCondition(10, listTable.get(size - 1).getItemId());
            if (list.size() < 10) {
                finish = true;
            }
            for (int i = 0; i < list.size(); i++) {
                listTable.add(list.get(i));
            }
            items = new ListDataModel(listTable);
        } catch (Exception e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("ERROR: " + e.getMessage()));
            e.printStackTrace();
        }
        return "";
    }
}
